package com.example.yuejian.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejian.Bean.Information;
import com.example.yuejian.R;
import com.example.yuejian.UnitData;
import com.example.yuejian.activity.HelpAndFeedback;
import com.example.yuejian.activity.MyAttention;
import com.example.yuejian.activity.MyPost;
import com.example.yuejian.activity.Order;
import com.example.yuejian.activity.UserInfo;
import com.example.yuejian.listener.ClubListener;
import com.example.yuejian.model.UserModel;
import com.squareup.picasso.Picasso;




public class fragment_me extends Fragment implements ClubListener<Information>,View.OnClickListener {
    private  View view =null;
    private ImageView mir_d;
    private LinearLayout ly1,ly2,ly3,ly4,ly5,clear_menmory,help_and_feedback,logout;
    private TextView t2;
    private  Intent intent = new Intent();
    private  String pic,name,phone,ads;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view=inflater.inflate(R.layout.mydetail, container, false);

        initview();
        Event();
        Event();
        return  view;

    }
    private void initview(){
        UserModel userModel = new UserModel();
        userModel.clubData(this);
        ly1 = (LinearLayout)view.findViewById(R.id.ly_user);
        ly2 = (LinearLayout)view.findViewById(R.id.ly_order);
        ly3 = (LinearLayout)view.findViewById(R.id.ly_post);
        ly4 = (LinearLayout)view.findViewById(R.id.ly_attention);
        ly5 = (LinearLayout)view.findViewById(R.id.ly_setting);
        logout = (LinearLayout)view.findViewById(R.id.logout);
        clear_menmory = (LinearLayout)view.findViewById(R.id.clear_menmory);
        help_and_feedback = (LinearLayout)view.findViewById(R.id.help_and_feedback);
        mir_d = (ImageView)view.findViewById(R.id.mir_d);
        t2 = (TextView)view.findViewById(R.id.name);


    }
    private void Event(){
        ly1.setOnClickListener(this);
        ly2.setOnClickListener(this);
        ly3.setOnClickListener(this);
        ly4.setOnClickListener(this);
        ly5.setOnClickListener(this);
        logout.setOnClickListener(this);
        clear_menmory.setOnClickListener(this);
        help_and_feedback.setOnClickListener(this);



    }

    @Override
    public void onResponse(Information user) {

            Picasso.with(getActivity()).load(UnitData.IMG_URL+
                    user.getUser_picture()).into(mir_d);

        pic = UnitData.IMG_URL+ user.getUser_picture();
        name = user.getUser_telphone();
        phone = user.getUser_name();
        ads = user.getAddress();


            t2.setText(user.getUser_name());


    }

    @Override
    public void onFail(String msg) {
        System.out.println("+++++"+"失败");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.ly_order:
                intent.setClass(getActivity(), Order.class);
                startActivity(intent);
                break;
            case R.id.ly_post:
                intent.setClass(getActivity(), MyPost.class);
                startActivity(intent);
                break;
            case R.id.ly_attention:
                intent.setClass(getActivity(), MyAttention.class);
                startActivity(intent);
                break;
            case R.id.ly_setting:
                intent.setClass(getActivity(), UserInfo.class);
                startActivity(intent);
                break;
            case R.id.clear_menmory:
                intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                Uri uri1=Uri.parse("package:" + getActivity().getPackageName());
                intent.setData(uri1);
                startActivity(intent);
                break;
            case R.id.help_and_feedback:
                intent.setClass(getActivity(), HelpAndFeedback.class);
                startActivity(intent);
                break;
            case R.id.logout:
               getActivity().finish();
                break;
            default:
                break;

        }
    }
}

